package com.koron.css2.baseConfig.impl;

import com.github.pagehelper.PageInfo;
import com.koron.css2.ServerInterface;
import com.koron.css2.baseConfig.bean.BaseInvoiceTypeBean;
import com.koron.css2.baseConfig.mapper.BaseInvoiceTypeMapper;
import com.koron.css2.baseConfig.vo.BaseInvoiceTypeListVO;
import com.koron.css2.serviceManage.bean.RequestBean;
import com.koron.css2.serviceManage.bean.UserInfoBean;
import com.koron.util.Constant;
import com.koron.util.JsonUtils;
import org.koron.ebs.mybatis.SessionFactory;
import org.swan.bean.MessageBean;

import java.util.List;

public class BaseInvoiceTypeOnList implements ServerInterface {

	@Override
	public MessageBean<?> exec(SessionFactory factory, UserInfoBean userInfo, RequestBean req) {
		@SuppressWarnings("rawtypes")
		MessageBean<PageInfo> info = MessageBean.create(Constant.MESSAGE_INT_SUCCESS, "success", PageInfo.class);
		try {
			BaseInvoiceTypeBean bean = JsonUtils.objectToPojo(req.getData(), BaseInvoiceTypeBean.class);
			BaseInvoiceTypeMapper mapper = factory.getMapper(BaseInvoiceTypeMapper.class);

			List<BaseInvoiceTypeListVO> list = mapper.selectOnList(bean);
			for (BaseInvoiceTypeListVO vo : list) {
				if("0".equals(vo.getStatus())) {
					vo.setStatusName("启用");
				}else if("1".equals(vo.getStatus())){
					vo.setStatusName("停用");
				}
			}
			info.setData(new PageInfo<>(list));
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return info;
	}

}
